package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;


    /**
     * 根据房间id查询房间内的床位
     *
     * @param roomId 房间ID
     * @return
     */
    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {

        return bedMapper.getBedsByRoomId(roomId);
    }

    /**
     * 创建床位
     *
     * @param bedDto
     */
    @Override
    public void create(BedDto bedDto) {
        Bed bed = BeanUtil.toBean(bedDto, Bed.class);//Mapper层一定要用pojo
        bed.setCreateTime(LocalDateTime.now());
        bed.setUpdateTime(LocalDateTime.now());
        /*设置床位状态*/
        bed.setBedStatus(0);//表示未入住
        bed.setCreateBy(123L);
        bed.setUpdateBy(123L);

        bedMapper.create(bed);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Override
    public BedVo read(Long id) {

        Bed bed = bedMapper.read(id);
        return BeanUtil.toBean(bed, BedVo.class);
    }

    /**
     * 更新
     *
     * @param bedDto
     */
    @Override
    public void update(BedDto bedDto) {
        Bed bed = BeanUtil.toBean(bedDto, Bed.class);
        bed.setUpdateTime(LocalDateTime.now());
        bed.setUpdateBy(123L);
        bedMapper.update(bed);
    }

    /**
     * 删除
     *
     * @param id
     */
    @Override
    public void delete(Long id) {

        bedMapper.delete(id);
    }
}

